home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14559 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to detect EOF?/filepointer problem.
  5. Date: Mon, 15 Apr 96 18:03:37 GMT
  6. Organization: none
  7. Message-ID: <829591417snz@genesis.demon.co.uk>
  8. References: <316F8932.2BAF@www.partio.fi> <NEWTNews.829550737.4541.ggil@dialup.netvision.net.il>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <NEWTNews.829550737.4541.ggil@dialup.netvision.net.il>
  15.            ggil@netvision.net.il  writes:
  16.  
  17. >
  18. >In Article<316F8932.2BAF@www.partio.fi>, <ralph@www.partio.fi> writes:
  19. >> Path: 
  20.  
  21. >> Sorry to bother you, but I have a problem 
  22. >> while scanning through a file too see whether 
  23. >> or not a certain word occurs.
  24. >> When I run out of file, fscanf() keeps 
  25. >> returning the last line, instead of some NULL 
  26. >> value I would find logical (but who am I?).
  27. >> 
  28. >> How can I test for the end of the file?
  29. >
  30. >If you use fgets() instead you may avoid many problems
  31. >( it returns NULL on EOF )
  32.  
  33. It returns a null pointer in end-of-file if it hasn't written any
  34. characters to the buffer. If it encounters end-of-file after writing
  35. some characters (but not '\n') then the next call to fgets() returns
  36. a null pointer.
  37.  
  38. fscanf() works in a similar way - it returns EOF if end-of-file was
  39. encountered before any successful conversion occurred. However fgets()
  40. is more appropriate than fscanf() for line based input for other reasons.
  41.  
  42. -- 
  43. -----------------------------------------
  44. Lawrence Kirby | fred@genesis.demon.co.uk
  45. Wilts, England | 70734.126@compuserve.com
  46. -----------------------------------------
  47.